using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Portal.BO.Editoral.NewsEditModules;
using Portal.BO.Editoral.ModuleConfig;

namespace Portal.GUI.EditoralOffice.MainOffce.NewsEditModules
{
    public partial class ModuleEdit : System.Web.UI.Page
    {
        Portal.API.Module editCtr;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["modulePath"] != null)
                {
                    ModuleCommon module = new ModuleCommon();
                    string strModule = Request.Params["modulePath"];
                    if (!strModule.StartsWith("/GUI"))
                        strModule = "/GUI" + strModule;

                    module.ConfigFileLocation = strModule;
                    module.LoadModuleSettings();
                    
                    editCtr = (Portal.API.Module)LoadControl(strModule + "/" + module.ModuleSettings.editCtrl);
                    string moduleRef = "";
                    if (Request.Params["moduleReference"] != null)
                    {
                        ViewState["moduleref"] = Request.Params["moduleReference"];
                    }

                    if (ViewState["moduleref"] == null)
                        ViewState["moduleref"] = System.Guid.NewGuid().ToString();

                    moduleRef = Convert.ToString(ViewState["moduleref"]);

                    editCtr.InitModule(null, moduleRef, Request.Params["modulePath"], "~/GUI" + Request.Params["modulePath"], true);
                    editCtr.ID = "GeneralEditControl";
                    dvContainer.Controls.Add(editCtr);
                }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            ((Portal.BO.Editoral.NewsEditModules.NewsModule)editCtr).SaveAllProperties();
        }
    }
}
